"use strict";function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}function _defineProperties(target,props){for(var i=0;i=1;var easedProgress=completed?1:this.easing(linearProgress);this.value=this.from+(this.to-this.from)*easedProgress}else this.lerp?(this.value=damp(this.value,this.to,this.lerp*60,deltaTime),Math.round(this.value)===this.to&&(this.value=this.to,completed=!0)):(this.value=this.to,completed=!0);completed&&this.stop(),(_a=this.onUpdate)===null||_a===void 0?void 0:_a.call(this,this.value,completed)}},{key:"stop",value:function stop(){this.isRunning=!1}},{key:"fromTo",value:function fromTo(from,to,_ref){var lerp=_ref.lerp,duration=_ref.duration,easing=_ref.easing,onStart=_ref.onStart,onUpdate=_ref.onUpdate;this.from=this.value=from,this.to=to,this.lerp=lerp,this.duration=duration,this.easing=easing,this.currentTime=0,this.isRunning=!0,onStart===null||onStart===void 0?void 0:onStart(),this.onUpdate=onUpdate}}]),Animate}(),Dimensions=function(){function Dimensions(){var _this=this,_ref2=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{},wrapper=_ref2.wrapper,content=_ref2.content,_ref2$autoResize=_ref2.autoResize,autoResize=_ref2$autoResize===void 0?!0:_ref2$autoResize,_ref2$debounce=_ref2.debounce,debounceValue=_ref2$debounce===void 0?250:_ref2$debounce;_classCallCheck(this,Dimensions),this.width=0,this.height=0,this.scrollWidth=0,this.scrollHeight=0,this.resize=function(){_this.onWrapperResize(),_this.onContentResize()},this.onWrapperResize=function(){_this.wrapper===window?(_this.width=window.innerWidth,_this.height=window.innerHeight):_this.wrapper instanceof HTMLElement&&(_this.width=_this.wrapper.clientWidth,_this.height=_this.wrapper.clientHeight)},this.onContentResize=function(){_this.wrapper===window?(_this.scrollHeight=_this.content.scrollHeight,_this.scrollWidth=_this.content.scrollWidth):_this.wrapper instanceof HTMLElement&&(_this.scrollHeight=_this.wrapper.scrollHeight,_this.scrollWidth=_this.wrapper.scrollWidth)},this.wrapper=wrapper,this.content=content,autoResize&&(this.debouncedResize=debounce(this.resize,debounceValue),this.wrapper===window?window.addEventListener("resize",this.debouncedResize,!1):(this.wrapperResizeObserver=new ResizeObserver(this.debouncedResize),this.wrapperResizeObserver.observe(this.wrapper)),this.contentResizeObserver=new ResizeObserver(this.debouncedResize),this.contentResizeObserver.observe(this.content)),this.resize()}return _createClass(Dimensions,[{key:"destroy",value:function destroy(){var _a,_b;(_a=this.wrapperResizeObserver)===null||_a===void 0?void 0:_a.disconnect(),(_b=this.contentResizeObserver)===null||_b===void 0?void 0:_b.disconnect(),window.removeEventListener("resize",this.debouncedResize,!1)}},{key:"limit",get:function get(){return{x:this.scrollWidth-this.width,y:this.scrollHeight-this.height}}}]),Dimensions}(),Emitter=function(){function Emitter(){_classCallCheck(this,Emitter),this.events={}}return _createClass(Emitter,[{key:"emit",value:function emit(event){var callbacks=this.events[event]||[];for(var _len=arguments.length,args=new Array(_len>1?_len-1:0),_key=1;_key<_len;_key++)args[_key-1]=arguments[_key];for(var i=0,length=callbacks.length;i0&&arguments[0]!==undefined?arguments[0]:{},_ref6$wrapper=_ref6.wrapper,wrapper=_ref6$wrapper===void 0?window:_ref6$wrapper,_ref6$content=_ref6.content,content=_ref6$content===void 0?document.documentElement:_ref6$content,_ref6$wheelEventsTarg=_ref6.wheelEventsTarget,wheelEventsTarget=_ref6$wheelEventsTarg===void 0?wrapper:_ref6$wheelEventsTarg,_ref6$eventsTarget=_ref6.eventsTarget,eventsTarget=_ref6$eventsTarget===void 0?wheelEventsTarget:_ref6$eventsTarget,_ref6$smoothWheel=_ref6.smoothWheel,smoothWheel=_ref6$smoothWheel===void 0?!0:_ref6$smoothWheel,_ref6$syncTouch=_ref6.syncTouch,syncTouch=_ref6$syncTouch===void 0?!1:_ref6$syncTouch,_ref6$syncTouchLerp=_ref6.syncTouchLerp,syncTouchLerp=_ref6$syncTouchLerp===void 0?.075:_ref6$syncTouchLerp,_ref6$touchInertiaMul=_ref6.touchInertiaMultiplier,touchInertiaMultiplier=_ref6$touchInertiaMul===void 0?35:_ref6$touchInertiaMul,duration=_ref6.duration,_ref6$easing=_ref6.easing,easing=_ref6$easing===void 0?function(t){return Math.min(1,1.001-Math.pow(2,-10*t))}:_ref6$easing,_ref6$lerp=_ref6.lerp,lerp=_ref6$lerp===void 0?.1:_ref6$lerp,_ref6$infinite=_ref6.infinite,infinite=_ref6$infinite===void 0?!1:_ref6$infinite,_ref6$orientation=_ref6.orientation,orientation=_ref6$orientation===void 0?"vertical":_ref6$orientation,_ref6$gestureOrientat=_ref6.gestureOrientation,gestureOrientation=_ref6$gestureOrientat===void 0?"vertical":_ref6$gestureOrientat,_ref6$touchMultiplier=_ref6.touchMultiplier,touchMultiplier=_ref6$touchMultiplier===void 0?1:_ref6$touchMultiplier,_ref6$wheelMultiplier=_ref6.wheelMultiplier,wheelMultiplier=_ref6$wheelMultiplier===void 0?1:_ref6$wheelMultiplier,_ref6$autoResize=_ref6.autoResize,autoResize=_ref6$autoResize===void 0?!0:_ref6$autoResize,prevent=_ref6.prevent,virtualScroll=_ref6.virtualScroll,_ref6$__experimental_=_ref6.__experimental__naiveDimensions,__experimental__naiveDimensions=_ref6$__experimental_===void 0?!1:_ref6$__experimental_;_classCallCheck(this,Lenis),this.__isScrolling=!1,this.__isStopped=!1,this.__isLocked=!1,this.userData={},this.lastVelocity=0,this.velocity=0,this.direction=0,this.onPointerDown=function(event){event.button===1&&_this4.reset()},this.onVirtualScroll=function(data){if(typeof _this4.options.virtualScroll=="function"&&_this4.options.virtualScroll(data)===!1)return;var deltaX=data.deltaX,deltaY=data.deltaY,event=data.event;_this4.emitter.emit("virtual-scroll",{deltaX:deltaX,deltaY:deltaY,event:event});if(event.ctrlKey)return;var isTouch=event.type.includes("touch"),isWheel=event.type.includes("wheel");_this4.isTouching=event.type==="touchstart"||event.type==="touchmove";var isTapToStop=_this4.options.syncTouch&&isTouch&&event.type==="touchstart"&&!_this4.isStopped&&!_this4.isLocked;if(isTapToStop){_this4.reset();return}var isClick=deltaX===0&&deltaY===0,isUnknownGesture=_this4.options.gestureOrientation==="vertical"&&deltaY===0||_this4.options.gestureOrientation==="horizontal"&&deltaX===0;if(isClick||isUnknownGesture)return;var composedPath=event.composedPath();composedPath=composedPath.slice(0,composedPath.indexOf(_this4.rootElement));var prevent=_this4.options.prevent;if(!!composedPath.find(function(node){var _a,_b,_c,_d,_e;return node instanceof Element&&(typeof prevent=="function"&&(prevent===null||prevent===void 0?void 0:prevent(node))||((_a=node.hasAttribute)===null||_a===void 0?void 0:_a.call(node,"data-lenis-prevent"))||isTouch&&((_b=node.hasAttribute)===null||_b===void 0?void 0:_b.call(node,"data-lenis-prevent-touch"))||isWheel&&((_c=node.hasAttribute)===null||_c===void 0?void 0:_c.call(node,"data-lenis-prevent-wheel"))||((_d=node.classList)===null||_d===void 0?void 0:_d.contains("lenis"))&&((_e=node.classList)===null||_e===void 0?!void 0:!_e.contains("lenis-stopped")))}))return;if(_this4.isStopped||_this4.isLocked){event.preventDefault();return}var isSmooth=_this4.options.syncTouch&&isTouch||_this4.options.smoothWheel&&isWheel;if(!isSmooth){_this4.isScrolling="native",_this4.animate.stop();return}event.preventDefault();var delta=deltaY;_this4.options.gestureOrientation==="both"?delta=Math.abs(deltaY)>Math.abs(deltaX)?deltaY:deltaX:_this4.options.gestureOrientation==="horizontal"&&(delta=deltaX);var syncTouch=isTouch&&_this4.options.syncTouch,isTouchEnd=isTouch&&event.type==="touchend",hasTouchInertia=isTouchEnd&&Math.abs(delta)>5;hasTouchInertia&&(delta=_this4.velocity*_this4.options.touchInertiaMultiplier),_this4.scrollTo(_this4.targetScroll+delta,Object.assign({programmatic:!1},syncTouch?{lerp:hasTouchInertia?_this4.options.syncTouchLerp:1}:{lerp:_this4.options.lerp,duration:_this4.options.duration,easing:_this4.options.easing}))},this.onNativeScroll=function(){clearTimeout(_this4.__resetVelocityTimeout),delete _this4.__resetVelocityTimeout;if(_this4.__preventNextNativeScrollEvent){delete _this4.__preventNextNativeScrollEvent;return}if(_this4.isScrolling===!1||_this4.isScrolling==="native"){var lastScroll=_this4.animatedScroll;_this4.animatedScroll=_this4.targetScroll=_this4.actualScroll,_this4.lastVelocity=_this4.velocity,_this4.velocity=_this4.animatedScroll-lastScroll,_this4.direction=Math.sign(_this4.animatedScroll-lastScroll),_this4.isScrolling="native",_this4.emit(),_this4.velocity!==0&&(_this4.__resetVelocityTimeout=setTimeout(function(){_this4.lastVelocity=_this4.velocity,_this4.velocity=0,_this4.isScrolling=!1,_this4.emit()},400))}},window.lenisVersion=version;if(!wrapper||wrapper===document.documentElement||wrapper===document.body)wrapper=window;this.options={wrapper:wrapper,content:content,wheelEventsTarget:wheelEventsTarget,eventsTarget:eventsTarget,smoothWheel:smoothWheel,syncTouch:syncTouch,syncTouchLerp:syncTouchLerp,touchInertiaMultiplier:touchInertiaMultiplier,duration:duration,easing:easing,lerp:lerp,infinite:infinite,gestureOrientation:gestureOrientation,orientation:orientation,touchMultiplier:touchMultiplier,wheelMultiplier:wheelMultiplier,autoResize:autoResize,prevent:prevent,virtualScroll:virtualScroll,__experimental__naiveDimensions:__experimental__naiveDimensions},this.animate=new Animate,this.emitter=new Emitter,this.dimensions=new Dimensions({wrapper:wrapper,content:content,autoResize:autoResize}),this.updateClassName(),this.userData={},this.time=0,this.velocity=this.lastVelocity=0,this.isLocked=!1,this.isStopped=!1,this.isScrolling=!1,this.targetScroll=this.animatedScroll=this.actualScroll,this.options.wrapper.addEventListener("scroll",this.onNativeScroll,!1),this.options.wrapper.addEventListener("pointerdown",this.onPointerDown,!1),this.virtualScroll=new VirtualScroll(eventsTarget,{touchMultiplier:touchMultiplier,wheelMultiplier:wheelMultiplier}),this.virtualScroll.on("scroll",this.onVirtualScroll)}return _createClass(Lenis,[{key:"destroy",value:function destroy(){this.emitter.destroy(),this.options.wrapper.removeEventListener("scroll",this.onNativeScroll,!1),this.options.wrapper.removeEventListener("pointerdown",this.onPointerDown,!1),this.virtualScroll.destroy(),this.dimensions.destroy(),this.cleanUpClassName()}},{key:"on",value:function on(event,callback){return this.emitter.on(event,callback)}},{key:"off",value:function off(event,callback){return this.emitter.off(event,callback)}},{key:"setScroll",value:function setScroll(scroll){this.isHorizontal?this.rootElement.scrollLeft=scroll:this.rootElement.scrollTop=scroll}},{key:"resize",value:function resize(){this.dimensions.resize()}},{key:"emit",value:function emit(){this.emitter.emit("scroll",this)}},{key:"reset",value:function reset(){this.isLocked=!1,this.isScrolling=!1,this.animatedScroll=this.targetScroll=this.actualScroll,this.lastVelocity=this.velocity=0,this.animate.stop()}},{key:"start",value:function start(){if(!this.isStopped)return;this.isStopped=!1,this.reset()}},{key:"stop",value:function stop(){if(this.isStopped)return;this.isStopped=!0,this.animate.stop(),this.reset()}},{key:"raf",value:function raf(time){var deltaTime=time-(this.time||time);this.time=time,this.animate.advance(deltaTime*.001)}},{key:"scrollTo",value:function scrollTo(target){var _this5=this,_ref7=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},_ref7$offset=_ref7.offset,offset=_ref7$offset===void 0?0:_ref7$offset,_ref7$immediate=_ref7.immediate,immediate=_ref7$immediate===void 0?!1:_ref7$immediate,_ref7$lock=_ref7.lock,lock=_ref7$lock===void 0?!1:_ref7$lock,_ref7$duration=_ref7.duration,duration=_ref7$duration===void 0?this.options.duration:_ref7$duration,_ref7$easing=_ref7.easing,easing=_ref7$easing===void 0?this.options.easing:_ref7$easing,_ref7$lerp=_ref7.lerp,lerp=_ref7$lerp===void 0?this.options.lerp:_ref7$lerp,_onStart=_ref7.onStart,onComplete=_ref7.onComplete,_ref7$force=_ref7.force,force=_ref7$force===void 0?!1:_ref7$force,_ref7$programmatic=_ref7.programmatic,programmatic=_ref7$programmatic===void 0?!0:_ref7$programmatic,_ref7$userData=_ref7.userData,userData=_ref7$userData===void 0?{}:_ref7$userData;if((this.isStopped||this.isLocked)&&!force)return;if(typeof target=="string"&&["top","left","start"].includes(target))target=0;else if(typeof target=="string"&&["bottom","right","end"].includes(target))target=this.limit;else{var node;typeof target=="string"?node=document.querySelector(target):target instanceof HTMLElement&&(target===null||target===void 0?void 0:target.nodeType)&&(node=target);if(node){if(this.options.wrapper!==window){var wrapperRect=this.rootElement.getBoundingClientRect();offset-=this.isHorizontal?wrapperRect.left:wrapperRect.top}var rect=node.getBoundingClientRect();target=(this.isHorizontal?rect.left:rect.top)+this.animatedScroll}}if(typeof target!="number")return;target+=offset,target=Math.round(target),this.options.infinite?programmatic&&(this.targetScroll=this.animatedScroll=this.scroll):target=clamp(0,target,this.limit);if(target===this.targetScroll)return;this.userData=userData;if(immediate){this.animatedScroll=this.targetScroll=target,this.setScroll(this.scroll),this.reset(),this.preventNextNativeScrollEvent(),this.emit(),onComplete===null||onComplete===void 0?void 0:onComplete(this),this.userData={};return}programmatic||(this.targetScroll=target),this.animate.fromTo(this.animatedScroll,target,{duration:duration,easing:easing,lerp:lerp,onStart:function onStart(){lock&&(_this5.isLocked=!0),_this5.isScrolling="smooth",_onStart===null||_onStart===void 0?void 0:_onStart(_this5)},onUpdate:function onUpdate(value,completed){_this5.isScrolling="smooth",_this5.lastVelocity=_this5.velocity,_this5.velocity=value-_this5.animatedScroll,_this5.direction=Math.sign(_this5.velocity),_this5.animatedScroll=value,_this5.setScroll(_this5.scroll),programmatic&&(_this5.targetScroll=value),completed||_this5.emit(),completed&&(_this5.reset(),_this5.emit(),onComplete===null||onComplete===void 0?void 0:onComplete(_this5),_this5.userData={},_this5.preventNextNativeScrollEvent())}})}},{key:"preventNextNativeScrollEvent",value:function preventNextNativeScrollEvent(){var _this6=this;this.__preventNextNativeScrollEvent=!0,requestAnimationFrame(function(){delete _this6.__preventNextNativeScrollEvent})}},{key:"rootElement",get:function get(){return this.options.wrapper===window?document.documentElement:this.options.wrapper}},{key:"limit",get:function get(){return this.options.__experimental__naiveDimensions?this.isHorizontal?this.rootElement.scrollWidth-this.rootElement.clientWidth:this.rootElement.scrollHeight-this.rootElement.clientHeight:this.dimensions.limit[this.isHorizontal?"x":"y"]}},{key:"isHorizontal",get:function get(){return this.options.orientation==="horizontal"}},{key:"actualScroll",get:function get(){return this.isHorizontal?this.rootElement.scrollLeft:this.rootElement.scrollTop}},{key:"scroll",get:function get(){return this.options.infinite?modulo(this.animatedScroll,this.limit):this.animatedScroll}},{key:"progress",get:function get(){return this.limit===0?1:this.scroll/this.limit}},{key:"isScrolling",get:function get(){return this.__isScrolling},set:function set(value){this.__isScrolling!==value&&(this.__isScrolling=value,this.updateClassName())}},{key:"isStopped",get:function get(){return this.__isStopped},set:function set(value){this.__isStopped!==value&&(this.__isStopped=value,this.updateClassName())}},{key:"isLocked",get:function get(){return this.__isLocked},set:function set(value){this.__isLocked!==value&&(this.__isLocked=value,this.updateClassName())}},{key:"isSmooth",get:function get(){return this.isScrolling==="smooth"}},{key:"className",get:function get(){var className="lenis";return this.isStopped&&(className+=" lenis-stopped"),this.isLocked&&(className+=" lenis-locked"),this.isScrolling&&(className+=" lenis-scrolling"),this.isScrolling==="smooth"&&(className+=" lenis-smooth"),className}},{key:"updateClassName",value:function updateClassName(){this.cleanUpClassName(),this.rootElement.className="".concat(this.rootElement.className," ").concat(this.className).trim()}},{key:"cleanUpClassName",value:function cleanUpClassName(){this.rootElement.className=this.rootElement.className.replace(/lenis(-\w+)?/g,"").trim()}}]),Lenis}();return Lenis})